<template>
    <div class="salaryList">
        <van-nav-bar title="工资记录" left-arrow @click-left="$router.go(-1)" />
        <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
            <div class="container">
                <div v-if='noData' class="noData">
                    暂无工资记录
                </div>
                <template v-else>
                    <van-list v-model="loading" :finished="finished" finished-text="- 没有更多了 -" @load="onLoad"
                        :offset="130">
                        <div v-for="item in salaryList" :key="item.id" class="salary_item">
                            <van-row type="flex" justify="space-between" align="center" class="row_info">
                                <van-col span="22">
                                    发薪时间：
                                    <span>{{item.fsalaryTime}}</span>
                                </van-col>
                            </van-row>
                            <van-row type="flex" justify="space-between" align="center" class="row_info">
                                <van-col span="16">
                                    实发金额：
                                    <span style="font-weight: bold; color: black;">{{ item.fsalary }}元</span>
                                </van-col>
                                <van-col span="6" class="btn">
                                    <van-button plain type="info" size="mini" @click.stop="goToSalaryDetailPage(item.id)">工资详情
                                    </van-button>
                                </van-col>
                            </van-row>
                        </div>
                    </van-list>
                </template>
            </div>
        </van-pull-refresh>
    </div>
</template>

<script>
import {Toast} from 'vant'

export default {
  name: 'salaryList',
  data() {
    return {
      page: 0,
      loading: false, // 当loading为true时，转圈圈
      finished: false, // 数据是否请求结束，结束会先显示- 没有更多了 -
      salaryList: [],
      noData: false, // 如果没有数据，显示暂无数据
      isLoading: false, // 下拉的加载图案

      jobuserid: '',
      jobId: ''
    }
  },
  components: {},

  created() {
    this.jobid = this.$route.query.jobid
    this.jobuserid = this.$route.query.jobuserid
  },

  mounted() {},
  methods: {
    getSalarySheetByJobUserId() {
      let params = {
        PageSize: 10,
        PageIndex: this.page,
        JobId: this.jobid,
        JobUserId: this.jobuserid
      }
      this.$api.myCompany.GetSalarySheetByJobUserId(params).then(res => {
        this.loading = false
        if (res.code === 200) {
          if (res.data.totalcount == 0 && this.page === 0) {
            this.noData = true
            return
          }

          if (res.data.items.ds && res.data.items.ds.length > 0) {
            this.salaryList = this.salaryList.concat(res.data.items.ds)
            this.page++
          } else {
            // 如果加载完毕，显示没有更多了
            this.finished = true
          }
        } else {
          Toast('请求失败请重试！')
        }
      })
    },
    // 列表加载
    onLoad() {
      setTimeout(() => {
        this.getSalarySheetByJobUserId()
        this.loading = true
      }, 2000)
    },
    onRefresh() {
      setTimeout(() => {
        // 重新初始化这些属性
        this.isLoading = false
        this.salaryList = []
        this.page = 1
        this.loading = false
        this.finished = false
        this.noData = false
        // 请求信息
        this.getSalarySheetByJobUserId()
      }, 2000)
    },

    // 工资详情
    goToSalaryDetailPage(salaryInfoId) {
      this.$router.push({
        path: `/wageDetail/${this.jobid}`,
        query: {
          jobuserid: this.jobuserid,
          salaryinfoid: salaryInfoId
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.salaryList {
  .noData {
    display: inline-block;
    width: 100%;
    margin: 5% auto;
    min-height: 80vh;
    color: #323233;
    font-weight: 500;
    font-size: 0.42667rem;
    text-align: center;
  }

  .salary_item {
    background-color: #ffffff;
    border-bottom: 0.6px solid #e6e6e6;
    margin: 0;
    padding: 9px 10px;
    font-size: 13px;
    color: #848484;

    .row_info {
      margin-top: 5px;
      flex-wrap: nowrap;
      .btn {
        text-align: right;
        white-space: nowrap;
      }
    }
  }
}
</style>